part of '../../repository.dart';

const _kAppStoreTransactionRevocationInfoTimeKey = 'time';
const _kAppStoreTransactionRevocationInfoReasonKey = 'reason';

class _AppStoreTransactionRevocationInfoDto extends Equatable {
  const _AppStoreTransactionRevocationInfoDto._internal({
    required this.timeDto,
    required this.reasonDto,
  });

  final ApiTimeDto timeDto;
  final _AppStoreTransactionRevocationReasonDto reasonDto;

  @override
  List<Object?> get props {
    return [
      timeDto,
      reasonDto,
    ];
  }

  factory _AppStoreTransactionRevocationInfoDto.fromJson(Map<String, dynamic> json) {
    final timeString = json[_kAppStoreTransactionRevocationInfoTimeKey] as String;
    final timeDto = ApiTimeDto.fromString(timeString);

    final reasonString = json[_kAppStoreTransactionRevocationInfoReasonKey] as String;
    final reasonDto = _AppStoreTransactionRevocationReasonDto.fromString(reasonString);

    return _AppStoreTransactionRevocationInfoDto._internal(
      timeDto: timeDto,
      reasonDto: reasonDto,
    );
  }

  AppStoreTransactionRevocationInfo toEntity() {
    return AppStoreTransactionRevocationInfo(
      time: timeDto.toEntity(),
      reason: reasonDto.toEntity(),
    );
  }
}
